<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<!--子组件中的输入框在输入框值改变时同时改变dnumber和num-->
<body>
<div id="app">
  <cpn v-bind:number1="num1" v-bind:number2="num2" @num1Change="input1change"
       @num2Change="input2change">
  </cpn>
</div>

<template id="cpn">
  <div>
    <!--num1与number1动态绑定-->
    <h1>props{{number1}}</h1>
    <!--number1与dnumber1动态绑定-->
    <h1>data{{dnumber1}}</h1>
    <input type="text" v-bind:value="dnumber1">

    <h1>props{{number2}}</h1>
    <h1>data{{dnumber2}}</h1>

    <input type="text" v-bind:value="dnumber2" @input="num2Input">
  </div>
</template>

<script src="../js/vue.js"></script>
<script>
  const cpn = {
    template: '#cpn',
    data() {
      return {
        dnumber1: this.number1,
        dnumber2: this.number2
      }
    },
    props: {
      number1: Number,
      number2: Number
    },
    methods: {
      num1Input(event) {
        this.dnumber1 = event.target.value
        console.log(this.dnumber1)
        this.$emit('num1change', this.dnumber1)
      },
      num2Input(event) {
        this.dnumber2 = event.target.value
        console.log(this.dnumber1)
        this.$emit('num2change', this.dnumber2)
      }
    }

  }
  const app = new Vue({
    el: '#app',
    data: {
      num1: 0,
      num2: 1
    },
    components: {
      cpn
    },
    methods: {
      input1change(item) {
        console.log('item', item)
        this.num1 = item
        console.log(item)
      },
      input2change(item) {
        this.num2 = item
        console.log(item)
      },
    }

  })
</script>
</body>
</html>
